package logic

import (
	"context"
	"time"
	"week1/textrpc/service"

	"week1/textrpc/internal/svc"
	"week1/textrpc/textrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type TextWeekDescLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewTextWeekDescLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TextWeekDescLogic {
	return &TextWeekDescLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *TextWeekDescLogic) TextWeekDesc(in *textrpc.TextWeekDescReq) (*textrpc.TextWeekDescRes, error) {
	// todo: add your logic here and delete this line
	weekTime := time.Now().Add(-time.Hour * 24 * 7).Format(time.DateTime)
	text, err := service.GetWeekDescAll(weekTime)
	if err != nil {
		return &textrpc.TextWeekDescRes{Data: nil}, err
	}
	var datas []*textrpc.TextData
	for _, v := range text {
		data := &textrpc.TextData{
			Id:        int32(v.ID),
			Title:     v.Title,
			Comment:   v.Comment,
			TypeId:    int32(v.TypeId),
			Tag:       v.Tag,
			LookCount: int32(v.LookCount),
			Status:    int32(v.Status),
		}
		datas = append(datas, data)
	}
	return &textrpc.TextWeekDescRes{Data: datas}, nil
}
